Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 17, 2025

This PR implements a new pathOf function that extracts property paths from lambda expressions, similar to the C# ExpressionUtils.PathOf functionality.

Features

The pathOf function takes a lambda expression and returns the property path as a string:

import { pathOf } from '@neolution-ch/javascript-utils';

// Simple property access
pathOf(x => x.prop); // Returns "prop"

// Nested property access
pathOf(x => x.nested.value); // Returns "nested.value"

// Deep nesting (matching the C# example)
pathOf(x => x.Recursion.Recursion.Recursion.Recursion); // Returns "Recursion.Recursion.Recursion.Recursion"

Implementation

The function uses JavaScript Proxy to intercept property access and build the path string:

  • Type-safe: Uses TypeScript generics with proper object constraints
  • Robust: Handles runtime errors gracefully with try-catch
  • Efficient: Uses a proxy-based approach to track property access without executing the actual expression
  • Well-documented: Includes comprehensive JSDoc documentation

Testing

Added 8 comprehensive test cases covering:

  • Simple property access
  • Nested property access
  • Deep property nesting
  • Different property types
  • Edge cases and error handling

All existing tests continue to pass (412 tests total), ensuring no regressions.

Code Quality

  • ✅ Passes all linting rules
  • ✅ Builds successfully
  • ✅ Follows prettier formatting
  • ✅ 96% code coverage (catch block safety net not covered, which is expected)

Fixes #14.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits July 17, 2025 13:02
Co-authored-by: manni497 <65862280+manni497@users.noreply.github.com>
…xpressions

Co-authored-by: manni497 <65862280+manni497@users.noreply.github.com>
Copilot AI changed the title [WIP] Function to get full path of nested object property Implement pathOf function for extracting property paths from lambda expressions Jul 17, 2025
Copilot AI requested a review from manni497 July 17, 2025 13:11
yarn.lock Outdated
@@ -4,37 +4,15 @@

"@ampproject/remapping@^2.2.0":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@ampproject/remapping/-/remapping-2.2.1.tgz#99e8e11851128b8702cd57c33684f1d0f260b630"
resolved "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I think you run the wrong command to install package depencies. Please undo this and package-lock.json and use 'yarn' instead of 'npm install' to install your dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! I've removed the package-lock.json file and restored yarn.lock to its original state, then used yarn to install dependencies. Commit e47fb70 addresses this issue.

… npm

Co-authored-by: manni497 <65862280+manni497@users.noreply.github.com>
Copilot AI requested a review from manni497 July 17, 2025 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Function to get full path of nested object property

2 participants